﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace nextGeneration_app
{
    public partial class teacher_login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                tbxLoginId.Focus();
         }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

            Session["loginID"] = tbxLoginId.Text;
            Session["loginPassword"] = tbxPassword.Text;

            if (tbxLoginId.Text != null && tbxPassword != null)
            {
                //check whether existing user or not 
                //from database SQL
                bool result = teacher_dbManager.teacherLogin(tbxLoginId.Text, tbxPassword.Text);
                if (result == true)
                {
                    
                    string typeOfUser = teacher_dbManager.checkTypeOfUser(tbxLoginId.Text, tbxPassword.Text);
                    if (typeOfUser == "TEACHER")
                    {
                        FormsAuthentication.RedirectFromLoginPage(tbxLoginId.Text, false);
                        Response.Redirect("teacher_profile.aspx");
                    }
                    else
                    {
                        lblLoginResult.Visible = true;
                        lblLoginResult.Text = " Login Failed!!!<br> " + " Invalid username or password ";
                    }
                }
            }
        }

   

        protected void btnReset_Click(object sender, EventArgs e)
        {
            tbxLoginId.Text = "";
            tbxPassword.Text = "";
            lblLoginResult.Visible = false;
        }
    }
}